﻿package mortal.game.view.forging.view
{
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.manager.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.resource.info.item.*;
    import mortal.game.resource.tableConfig.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.game.view.forging.*;
    import mortal.game.view.forging.renderer.*;
    import mortal.game.view.palyer.*;
    import mortal.mvc.interfaces.*;

    public class GemSelWin extends BaseWindow
    {
        private var _info:GTextFiled;
        private var _itemList:GTileList;
        private var _pageSelecter:PageSelecter;
        private var _selEquipData:ItemData;
        private var _gemList:Array;
        private static var _instance:GemSelWin;

        public function GemSelWin(param1:ILayer = null)
        {
            super(param1);
            setSize(248, 194);
            title = Language.getString(41157);
            this.layer = LayerManager.topLayer;
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(9, 60, 232, 97, this));
            this._info = UIFactory.gTextField("", 16, 40, 230, 20, this);
            this._itemList = UIFactory.tileList(14, 65, 250, 91, this);
            this._itemList.columnWidth = 44;
            this._itemList.rowHeight = 44;
            this._itemList.horizontalGap = 0;
            this._itemList.verticalGap = 0;
            this._itemList.setStyle("skin", new Bitmap());
            this._itemList.setStyle("cellRenderer", PackGemItemCellRenderer);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = AlignMode.CENTER;
            this._pageSelecter = UIFactory.pageSelecter(60, 165, this, PageSelecter.CompleteMode);
            this._pageSelecter.setbgStlye(ImagesConst.InputBg, _loc_1);
            this._pageSelecter.pageTextBoxSize = 50;
            this._pageSelecter.maxPage = 1;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            return;
        }// end function

        public function set data(param1:Object) : void
        {
            this._gemList = param1 as Array;
            var _loc_2:* = (GameController.forging.view as ForgingModule).equipDisplaySpr.currSelEquip;
            if (_loc_2)
            {
                this._selEquipData = _loc_2.itemData;
                this.updateTipInfo();
            }
            this.updatePageInfo();
            this.updateItemList();
            return;
        }// end function

        private function updateTipInfo() : void
        {
            var _loc_1:String = "";
            var _loc_2:* = this._selEquipData.itemInfo.type;
            var _loc_3:* = GameDefConfig.instance.getEquipName(_loc_2);
            var _loc_4:* = EquipJewelMatchConfig.instance.getJewelTypeByEquipType(_loc_2);
            var _loc_5:* = GameDefConfig.instance.getItem("FightRoleAttribute", _loc_4).text1 + Language.getString(41159);
            _loc_1 = Language.getStringByParam(41158, _loc_5);
            this._info.htmlText = _loc_1;
            return;
        }// end function

        private function updatePageInfo() : void
        {
            var _loc_1:* = Math.ceil(this._gemList.length / 10);
            this._pageSelecter.maxPage = _loc_1;
            return;
        }// end function

        private function updateItemList() : void
        {
            var _loc_1:* = (this._pageSelecter.currentPage - 1) * 10;
            var _loc_2:* = this._pageSelecter.currentPage * 10;
            var _loc_3:* = this._gemList.slice(_loc_1, _loc_2);
            var _loc_4:* = _loc_3.length;
            while (_loc_4 < 10)
            {
                
                _loc_3.push({});
                _loc_4++;
            }
            var _loc_5:* = new DataProvider();
            _loc_5.addItems(_loc_3);
            this._itemList.dataProvider = _loc_5;
            this._itemList.drawNow();
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this.updateItemList();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl(param1);
            this._info.dispose();
            this._info = null;
            this._itemList.dispose();
            this._itemList = null;
            this._pageSelecter.dispose();
            this._pageSelecter = null;
            this._selEquipData = null;
            this._gemList = null;
            return;
        }// end function

        public static function get instance() : GemSelWin
        {
            if (_instance == null)
            {
                _instance = new GemSelWin;
            }
            return _instance;
        }// end function

    }
}
